#include <algorithm>
#include <cstdio>
#include <queue>
#include <tuple>
constexpr int MaxN = 2e6 + 5;
class node
{
  public:
    int has;
    int id;
    int end;
    int depth;
    node *left, *right;
    node()
    {
        has = 0;
        id = 0;
        end = 0;
        depth = 0;
        left = nullptr;
        right = nullptr;
    }
};
class tnode
{
  public:
    int cur;
    int sync;
    int depth;
    tnode()
    {
        cur = 0;
        sync = 0;
        depth = 0;
    }
    tnode upstream(const tnode &a, const tnode &b)
    {
        tnode c;
        c.cur = a.depth < b.depth ? a.cur : b.cur;
        c.sync = a.depth < b.depth ? a.sync : b.sync;
        c.depth = std::min(a.depth, b.depth);
        return (*this = c);
    }
};
int n, m;
long long answer;
char s[MaxN];
tnode tree[MaxN * 4];
node *root;
void add(node *cur, char *s)
{
    char ch = *s++;
    if (ch == '\0')
    {
        cur->has++;
        return;
    }
    if (ch == '0')
    {
        if (!cur->left)
        {
            cur->left = new node;
            cur->left->depth = cur->depth + 1;
        }
        add(cur->left, s);
    }
    else
    {
        if (!cur->right)
        {
            cur->right = new node;
            cur->right->depth = cur->depth + 1;
        }
        add(cur->right, s);
    }
}
void format(node *cur)
{
    if (cur->has >= 1 && (!cur->left ^ !cur->right))
    {
        if (!cur->left)
        {
            cur->left = new node;
            cur->left->depth = cur->depth + 1;
            cur->left->has = 1;
            cur->has--;
            answer++;
        }
        if (!cur->right)
        {
            cur->right = new node;
            cur->right->depth = cur->depth + 1;
            cur->right->has = 1;
            cur->has--;
            answer++;
        }
    }
    if (cur->left || cur->right)
    {
        if (cur->left)
        {
            format(cur->left);
        }
        if (cur->right)
        {
            format(cur->right);
        }
        return;
    }
    int d = cur->has - 1;
    std::queue<node *> queue;
    queue.push(cur);
    for (; d >= 1;)
    {
        node *c = queue.front();
        queue.pop();
        c->has = 0;
        c->left = new node;
        c->right = new node;
        cur->left->depth = cur->depth + 1;
        cur->right->depth = cur->depth + 1;
        c->left->has = 1;
        c->right->has = 1;
        queue.push(c->left);
        queue.push(c->right);
        d--;
    }
}
void takeId(node *cur)
{
    cur->id = ++m;
    m += std::max(1, cur->has) - 1;
    if (cur->left)
    {
        takeId(cur->left);
    }
    if (cur->right)
    {
        takeId(cur->right);
    }
    cur->end = m;
}
void build(int c, int s, int t)
{
    if (s == t)
    {
        tree[c].cur = s;
        tree[c].depth = 0x3f3f3f3f;
        return;
    }
    int mid = (s + t) / 2;
    build(c * 2, s, mid);
    build(c * 2 + 1, mid + 1, t);
    tree[c].upstream(tree[c * 2], tree[c * 2 + 1]);
}
void change(int c, int s, int t, int w, std::tuple<int, int> val)
{
    if (s == t)
    {
        tree[c].depth = std::get<0>(val);
        tree[c].sync = std::get<1>(val);
        return;
    }
    int mid = (s + t) / 2;
    if (w <= mid)
    {
        change(c * 2, s, mid, w, val);
    }
    else
    {
        change(c * 2 + 1, mid + 1, t, w, val);
    }
    tree[c].upstream(tree[c * 2], tree[c * 2 + 1]);
}
tnode query(int c, int s, int t, int l, int r)
{
    if (l <= s && t <= r)
    {
        return tree[c];
    }
    int mid = (s + t) / 2;
    if (l <= mid && r > mid)
    {
        return tnode().upstream(query(c * 2, s, mid, l, r), query(c * 2 + 1, mid + 1, t, l, r));
    }
    else if (l <= mid)
    {
        return query(c * 2, s, mid, l, r);
    }
    else
    {
        return query(c * 2 + 1, mid + 1, t, l, r);
    }
}
void init(node *cur)
{
    if (cur->has == 0 && (!cur->left || !cur->right))
    {
        change(1, 1, m, cur->id, {cur->depth, 0});
    }
    if (cur->has == 1 && (!cur->left && !cur->right))
    {
        change(1, 1, m, cur->id, {cur->depth, cur->id});
    }
    if (cur->left)
    {
        init(cur->left);
    }
    if (cur->right)
    {
        init(cur->right);
    }
}
void dfs(node *cur)
{
    if ((cur->left || cur->right) && cur->has)
    {
        int d = cur->has;
        int begin = cur->id + cur->has;
        int end = cur->end;
        for (int i = d; i >= 1; i--)
        {
            cur->has--;
            auto r = query(1, 1, m, begin - (d - i), end);
            answer += r.depth - cur->depth + 1 + (r.sync == 0 ? 0 : 1);
            if (r.sync)
            {
                change(1, 1, m, r.cur, {r.depth + 1, r.sync});
            }
            change(1, 1, m, cur->id + i - 1, {r.depth + 1, cur->id + i - 1});
        }
    }
    if (cur->left)
    {
        dfs(cur->left);
    }
    if (cur->right)
    {
        dfs(cur->right);
    }
}
int main()
{
    freopen("id.in", "r", stdin);
    freopen("id.out", "w", stdout);
    scanf("%d", &n);
    root = new node;
    for (int i = 1; i <= n; i++)
    {
        scanf("%s", s);
        add(root, s);
    }
    format(root);
    takeId(root);
    build(1, 1, m);
    init(root);
    dfs(root);
    printf("%lld\n", answer);
    return 0;
}